package cn.schoolwow.util.test.module.query.jsonarray.flow.query;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.util.domain.query.jsonarray.QueryJSONArray;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.junit.Assert;

import java.util.Objects;

public class JSONQueryGetOneFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        JSONArray userArray = (JSONArray) flowContext.checkData("userArray");

        for(int i=0;i<userArray.size();i++){
            JSONObject user = userArray.getJSONObject(i);

            JSONObject queryUser = QueryJSONArray.newQuery(userArray)
                    .addQuery("username", user.getString("username"))
                    .addQuery("password", user.getString("password"))
                    .execute()
                    .getObject();
            Assert.assertTrue(Objects.equals(user, queryUser));
        }
    }

    @Override
    public String name() {
        return "用户单个JSON对象查询";
    }
}
